<?php
/**
 * [����ͨ System] Copyright swtshop.cn
 * QQ: 1170787711
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied');
class xuq_mod extends module
{
    function __construct()
    {
        $this->uid = @$_SESSION['user']['uid'];
        parent::__construct();
    }
    function get_one($id)
    {
        if (!empty($this->uid)) {
            if ($id) {
                $row = $this->db->get_one("select * from " . table('fbxq') . " where user_id = " . $this->uid . " and id = " . $id);
                if ($row['id']) {
                    if ($row['prov']) {
                        $prov_cn = $row['prov_cn'];
                    } else {
                        $prov_cn = '';
                    }
                    if ($row['city']) {
                        $city_cn = '/' . $row['city_cn'];
                    } else {
                        $city_cn = '';
                    }
                    if ($row['dist']) {
                        $dist_cn = '/' . $row['dist_cn'];
                    } else {
                        $dist_cn = '';
                    }
                    $row['area'] = $prov_cn . $city_cn . $dist_cn;
                    return $row;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    public function get_all()
    {
        if (!empty($this->uid)) {
            $list = $this->db->get_all("select a.*,b.name from " . table('fbxq') . " as a  left join swt_category as b on a.goods_fl=b.cid  where user_id = " . $this->uid . " order by addtime desc");
            if ($list) {
                foreach ($list as $k => $v) {
                    if ($v['prov']) {
                        $prov_cn = $v['prov_cn'];
                    } else {
                        $prov_cn == '';
                    }
                    if ($v['city']) {
                        $city_cn = ', ' . $v['city_cn'];
                    } else {
                        $city_cn == '';
                    }
                    if ($v['dist']) {
                        $dist_cn = ', ' . $v['dist_cn'];
                    } else {
                        $dist_cn == '';
                    }
                    $goods = unserialize($v['goods_guige']);
                    
                    $guige = '';
                    foreach ($goods as $g_value){
                    	foreach ($g_value as $g_k => $g_v){
                    		if($g_k == 0){
                    			$guige .= '<a class="guige">'.$g_v.'：</a>';
                    		}else{
                    			$guige .= $g_v;
                    		}
                    	}
                    }
                
                    $v['goods_guige'] = $guige;
                    $v['area'] = $prov_cn . $city_cn . $dist_cn;
                    $data[] = $v;
                }
                return $data;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    public function get_session_address()
    {
        $addr_ch = isset($_SESSION['settle_address']) ? $_SESSION['settle_address'] : '';
        if ($addr_ch) {
            $data = $this->db->get_one("select * from " . table('fbxq') . " where user_id = " . $this->uid . " and id = " . $addr_ch);
            if ($data['id']) {
                return $data;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

}